package com.manor.paradise.dialog

import android.content.Context
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.view.View
import com.lxj.xpopup.impl.FullScreenPopupView
import com.manor.common.utils.ClickUtil
import com.manor.paradise.R
import com.manor.paradise.bean.MineInfoBean
import com.manor.paradise.view.MineInfoListener
import kotlinx.android.synthetic.main.dialog_mineinfo_popup.view.*
import java.math.BigDecimal

/**
 * 矿山说明
 * @property mineInfoBean MineInfoBean
 * @property listener MineInfoListener
 * @constructor
 */
class MineInfoPopup(var mineInfoBean: MineInfoBean, context: Context, val listener: MineInfoListener) : FullScreenPopupView(context), View.OnClickListener {
    override fun getImplLayoutId(): Int {
        return R.layout.dialog_mineinfo_popup
    }

    override fun onCreate() {
        super.onCreate()
        im_dismiss.setOnClickListener(this)
        ll_jlxq.setOnClickListener(this)
        tv_mflq.setOnClickListener(this)
        if (mineInfoBean.price.compareTo(BigDecimal("0")) == 0) {
            tv_mflq.text = "免费领取"
        } else {
            tv_mflq.text = "雇佣"
        }


        tv_name.text = mineInfoBean.workplace
        tv_contents.text = mineInfoBean.contents
        var ind = "联盟" + mineInfoBean.name + "：" + mineInfoBean.totalNum + "只"

        var inde = "我的" + mineInfoBean.name + "：" + mineInfoBean.hireNum + "/" + mineInfoBean.sameNum + "只"
        val sta = ind.indexOf(mineInfoBean.name)
        val pp = SpannableString(inde)
        val foreng = ForegroundColorSpan(Color.parseColor("#FF3585FE"))
        pp.setSpan(foreng, sta+mineInfoBean.name.length+1, pp.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        tv_myjl.text = pp


    }


    override fun onClick(v: View?) {
        if (ClickUtil.canClick(500))
            when (v?.id) {
                R.id.im_dismiss -> {
                    dismiss()
                }
                R.id.ll_jlxq -> {
                    listener.onSelect(0)
                    dismiss()
                }
                R.id.tv_mflq -> {
                    listener.onSelect(1)
                    dismiss()
                }
            }
    }
}